clear
est clear


	use "$input/full_geoid_pair_panel.dta"
	

	
	bysort state_fips: egen max=max(storm)
		drop if max!=1
		
		
	
	
	drop if migration==.|migration==0
		g exp_difference=total_storms_fema-home_total_storms_fema
		bysort from_geoid move_year: egen avg_total_storms_fema=wtmean(total_storms_fema), weight(migration)
		bysort from_geoid move_year: egen avg_exp_difference=wtmean(exp_difference), weight(migration)
		bysort from_geoid move_year: egen total_migration=total(migration)
		
		duplicates drop from_geoid move_year, force
		
		ihstrans(avg_total_storms_fema avg_exp_difference)	
		
		label var storm "1(Storm year)"
	

			
		reghdfe ihs_avg_total_storms_fema i.storm [pweight=total_migration], absorb(i.from_geoid   i.move_year) vce(cluster state_fips)
		
			eststo t1c1
		reghdfe ihs_avg_exp_difference i.storm [pweight=total_migration], absorb(i.from_geoid   i.move_year) vce(cluster state_fips)
			eststo t1c2

			
	
	
		
	file open 	t 		using "$tables/table_si15.tex", replace write
	file write t	"\begin{table}[htbp]\footnotesize \centering" _n "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}" _n ///
						"\caption{Change in exposure for migrants using only FEMA storms}\label{tab: total exposure fema}" _n  ///
						"\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}}l*{9}{c}}" _n "\midrule" _n ///
						"&Destination exposure&Difference in exposure\\" _n ///
						"\midrule" _n 
	file close 	t
	
				esttab t1c* using "$tables/table_si15.tex", l keep(1.storm ) ///
				s(N, l("N") f(%11.0fc) lay(@)) $opts 
				
	file open 	t 		using "$tables/table_si15.tex", append write
	file write t "\\" ///
							"Fixed Effects:									&		&				\\" ///
							"\hspace{3mm}County								&Yes	&Yes			\\ " ///
							"\hspace{3mm}Year								&Yes	&Yes			\\ " ///
							"\midrule" _n "\end{tabular*}" _n ///
							"\begin{tabular*}{1\textwidth}{p{6.5in}}" _n ///
							"\footnotesize \textsc{Notes:} All columns report the results of a fixed effects specification. The outcome in column 1 is the IHS transformation of the average total number of storms experienced over our full sample in each of the counties that received migrants from a given sending county in a given year. The outcome in column 2 is the IHS transformation of the average difference in exposure between a sending county and all the counties that received migrants from that county in a given year. We only count storms as those that resulted in FEMA compensation. We calculate this difference as exposure in the sending county minus exposure in the receiving county for each sending-receiving pair in a given year, then averaged within sending counties and years. A more positive difference indicates that migrants moved to places with lower storm risk. This measure is the outcome in our regressions so a positive coefficient indicates that the average exposure difference is larger and more positive in storm years relative to non-storm years. That, in turn, indicates that in storm years migrants move to places with a greater reduction in risk between the county they leave and where they go compared to migrants who move in non-storm years. Regressions are weighted by the total migrants from a county in each year. Counties are defined as exposed to a storm if at least one hurricane resulted in a flood warning during the year or the county experienced wind speeds of at least 21 m/s - the speed at which structural damage begins to occur - during a hurricane in the year. \$^{*}\$p=0.1, \$^{**}\$p=0.05,\$^{***}\$p=0.01." ///
							"\end{tabular*}" _n "\end{table}" _n 
	file close 	t		
	
	
	
	